<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="区域" prop="region">
        <el-select clearable v-model="queryParams.region" placeholder="请选择">
          <el-option v-for="item in HL_SHNDZ_list" :key="item.Code" :label="item.Name" :value="item.Code">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="年度" prop="year">
        <el-input v-model="queryParams.year" placeholder="请输入年度" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="名称" prop="pername">
        <el-input v-model="queryParams.pername" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['administrative:holidayinformation:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['administrative:holidayinformation:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['administrative:holidayinformation:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['administrative:holidayinformation:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="holidayinformationList" @selection-change="handleSelectionChange"
      @current-change="rowclick" height="350">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="年度" align="center" prop="year" />
      <el-table-column label="工号" align="center" prop="percode" width="150" />
      <el-table-column label="名称" align="center" prop="pername" />
      <el-table-column label="区域" align="center" prop="region" />
      <el-table-column label="类别" align="center" prop="positioname" />
      <el-table-column label="职位" align="center" prop="levelname" width="150">
        <template slot-scope="scope">
          <el-tag>{{ scope.row.levelname }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="列假天数" align="center" prop="days" />
      <el-table-column label="年度剩余假期" align="center" prop="sxdays" width="150" />
      <el-table-column label="机票" align="center" prop="aircounts" />
      <el-table-column label="年度剩余机票" align="center" prop="sxair" width="150" />
      <el-table-column label="备注" align="center" prop="remark" width="180" />
      <el-table-column label="奖励天数" align="center" prop="adddays" />
      <el-table-column label="惩罚天数" align="center" prop="deledays" />
      <el-table-column label="总天数" align="center" prop="totaldays" />
      <el-table-column label="建档人" align="center" prop="operatorname" />
      <el-table-column label="上年度未休假期" align="center" prop="lastyeardays" width="150" />
      <el-table-column label="转下年度假期" align="center" prop="nextyeardays" width="150" />
      <el-table-column label="上年度剩余机票" align="center" prop="lastairdays" width="150" />
      <el-table-column label="转下年度机票" align="center" prop="nextairdays" width="150" />
      <el-table-column label="创建时间" align="center" prop="createtimes" width="200" />
      <el-table-column label="修改时间" align="center" prop="updatetimes" width="200" />
      <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['datalist:holidayinformation:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['datalist:holidayinformation:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <el-table :data="DataList2" style="width: 90%;margin: 0 auto;margin-top: 30px;" border height="300">
      <el-table-column prop="Year" label="年度">
      </el-table-column>
      <el-table-column prop="PerCode" label="工号">
      </el-table-column>
      <el-table-column prop="PerName" label="姓名">
      </el-table-column>
      <el-table-column prop="HolidayTypeName" label="假别">
      </el-table-column>
      <el-table-column prop="DtStart" label="开始日期" width="120">
      </el-table-column>
      <el-table-column prop="DtEnd" label="结束日期" width="120">
      </el-table-column>
      <el-table-column prop="Days" label="天数">
      </el-table-column>
      <el-table-column prop="Air" label="机票">
      </el-table-column>
      <el-table-column prop="dlname" label="职务代理人" width="100">
      </el-table-column>
      <el-table-column prop="Remark" label="备注" width="300">
      </el-table-column>
      <el-table-column prop="Operatorname" label="建档人">
      </el-table-column>
      <el-table-column prop="CreateTime" label="建档时间" width="250">
      </el-table-column>
    </el-table>
    <!-- 添加或修改假日信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="年度" prop="year">
              <el-input v-model="form.year" placeholder="请输入年度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工号" prop="percode">
              <el-input v-model="form.percode" placeholder="请输入工号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="姓名" prop="pername">
              <el-input v-model="form.pername" placeholder="请输入名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="区域" prop="region">
              <el-select clearable v-model="form.region" placeholder="请选择">
                <el-option v-for="item in HL_SHNDZ_list" :key="item.Code" :label="item.Name" :value="item.Code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="类别" prop="remark">
              <el-select clearable v-model="form.positioname" placeholder="请选择类别">
                <el-option v-for="item in SysPosition_list" :key="item.Code" :label="item.Name" :value="item.Code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职位" prop="DLPer">
              <el-select clearable v-model="form.levelname" placeholder="请选择类别">
                <el-option v-for="item in SysLevel_list" :key="item.Code" :label="item.Name" :value="item.Code">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="列假天数" prop="days">
              <el-input v-model="form.days" placeholder="请输入列假天数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="机票" prop="aircounts">
              <el-input v-model="form.aircounts" placeholder="请输入机票" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :span="24">
          <el-col :span="12">
            <el-form-item label="部门" prop="dptname">
              <el-input v-model="form.dptname" placeholder="请输入部门" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="入厂时间" prop="rzdate">
              <el-date-picker v-model="form.rzdate" type="date" placeholder="选择日期" format="yyyy/MM/dd"
                value-format="yyyy/MM/dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="职务代理人" prop="dlname">
          <el-input v-model="form.dlname" placeholder="请输入职务代理人" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listHolidayinformation, getHolidayinformation, delHolidayinformation,
  addHolidayinformation, updateHolidayinformation, Get_ID_HolidayMangement
} from "@/api/administrative/holidayinformation";
import {
  Get_public_SysLevel, Get_public_SysPosition,
  Get_public_SysHolidayType, Get_public_HL_SHNDZ
} from "@/api/publics/index";
import { log } from "console";

export default {
  name: "Holidayinformation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 假日信息表格数据
      holidayinformationList: [],
      //子表数据
      DataList2: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        year: null,
        percode: null,
        pername: null,
        region: null,
        mangement: null,
        position: null,
        levels: null,
        days: null,
        sxdays: null,
        aircounts: null,
        sxair: null,
        remark: null,
        operator: null,
        createtime: null,
        updatetime: null,
        adddays: null,
        deledays: null,
        totaldays: null,
        dlname: null,
        dptname: null,
        rzdate: null,
        company: null,
        lzdate: null,
        islz: null,
        lzclry: null,
        lastyeardays: null,
        nextyeardays: null,
        lastairdays: null,
        nextairdays: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 职称菜单
      SysLevel_list: [],
      // 职称菜单
      SysPosition_list: [],
      // 职称菜单
      SysHolidayType_list: [],
      // 职称菜单
      HL_SHNDZ_list: [],
    };
  },
  created() {
    this.getList();
    this.GetInit();
  },

  methods: {
    GetInit() {
      Get_public_SysLevel().then((res) => {
        this.SysLevel_list = res.data;
        // console.log("res", res.data);
      });
      Get_public_SysPosition().then((res) => {
        this.SysPosition_list = res.data;
        // console.log("res", res.data);
      });
      Get_public_SysHolidayType().then((res) => {
        this.SysHolidayType_list = res.data;
        // console.log("res", res.data);
      });
      Get_public_HL_SHNDZ().then((res) => {
        this.HL_SHNDZ_list = res.data;
        // console.log("res", res.data);
      });
    },
    rowclick(e) {
      Get_ID_HolidayMangement(e.id).then((res) => {
        console.log(res.data);
        this.DataList2 = res.data;
      });
    },
    /** 查询假日信息列表 */
    getList() {
      this.loading = true;
      listHolidayinformation(this.queryParams).then(response => {
        this.holidayinformationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        year: null,
        percode: null,
        pername: null,
        region: null,
        mangement: null,
        position: null,
        levels: null,
        days: null,
        sxdays: null,
        aircounts: null,
        sxair: null,
        remark: null,
        operator: null,
        createtime: null,
        updatetime: null,
        adddays: null,
        deledays: null,
        totaldays: null,
        dlname: null,
        dptname: null,
        rzdate: null,
        company: null,
        lzdate: null,
        islz: null,
        lzclry: null,
        lastyeardays: null,
        nextyeardays: null,
        lastairdays: null,
        nextairdays: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加假日信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHolidayinformation(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改假日信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHolidayinformation(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHolidayinformation(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除假日信息编号为"' + ids + '"的数据项？').then(function () {
        return delHolidayinformation(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('datalist/holidayinformation/export', {
        ...this.queryParams
      }, `holidayinformation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
